{use master_page('admin/v_master')} 
  
{block content}  

<?php 
	$cu_group = $this->usergroup_manager->get($this->current_user()->usergroup_id);  
?>

<script>
$(document).ready(function(){
	$('#type').change(function(){
		var v = $(this).val(); 
		<?
		$get_type = array_remove($_GET, 'type');
		$get_params = Array();
		foreach($_GET as $k=>$v)
		{
			$get_params[] = "$k=$v";
		}
		$get_params_str = implode('&',$get_params);
		?>
		var url = '<?=_U("usergroup/index?")?><?=$get_params_str?>&type=' + v;
		//alert(url);
		//window.open(url);
		window.location.href = url ;  
	}) ;

	$("#chkall").click(function(){
		var checked = $(this).attr("checked");
		$(".datatable tbody input[type=checkbox]").attr("checked",checked) ;  
	}) ; 
	
})
</script>
<?php
$ci = &get_instance(); 
$select_html = "<select id='parent_id' class='bind'><option value='0'>请选择</option>";
$ci->select_html = $select_html;
function bl_usergroup($usergroupes,$level=1)
{$ci = &get_instance(); 
?>
	<?php foreach($usergroupes as $usergroup):
	if(!empty($_GET['id'])):
	if($usergroup->id!=$_GET['id']):
		$ci->select_html .= "<option value='$usergroup->id'>".str_pad('--',$level)."$usergroup->name</option>";
	endif;
	else:
	$ci->select_html .= "<option value='$usergroup->id'>".str_pad('--',$level)."$usergroup->name</option>";
	endif;
	?>
	<tr> 
		<td style="width:60px;">
			<input type="checkbox" value="<?php echo $usergroup->id;?>" name="ids[]">
		</td>
		<td align="center">
			<span style="width:59px" class="hotspot">
				<input type="text" name="listorder[<?php echo $usergroup->id?>]" value="<?php echo $usergroup->order?>" class="input_c">
			</span>
		</td>
		<td align="center" width="90">{usergroup->id}</td> 
		<td align="left" style="padding-left:<?=$level*60?>px" width="200">
			└{usergroup->name}
		</td> 
		<td align="center" width="200"><?=$usergroup->type?></td>
		<td align="center" width="90"> 
			<?php if($cu_group->permission("usergroup","edit")):?>
			<a class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();" href="<?=_U('usergroup/edit?tab=system_manager&id=')?>{usergroup->id}">
			</a>
			<?php endif;?>
			<?php if($cu_group->permission("usergroup","del")):?>  
			<a class="delete" onmouseover="tooltip.show('删除');" onmouseout="tooltip.hide();" onclick="javascript:return confirm('删除用户组将会删除该组内用户，是否确认删除');" href="<?=_U('usergroup/del?tab=system_manager&id=')?>{usergroup->id}">
			</a>
			<?php endif;?>
		</td> 
	</tr>
	<?if(sizeof($usergroup->children)>0){bl_usergroup($usergroup->children,$level+1);}?> 
	<?php endforeach;?>
<?php
}
?>
<form id = 'form1' action = '<?=$_SERVER['REQUEST_URI']?>' method='post'>
	<div class="blank20" style="height:10px;"></div>
	<?php if($cu_group->permission("usergroup","edit")):?>
	<div style="padding-left:10px;">
		<input style="width:132px;height:38px;line-height:38px;color:white;background:url(images/btn_03.gif) left top no-repeat;border:none; text-align:center;
 			 cursor: pointer;" class="btn_c" type="button" value=" 添加用户组" 
 			 onclick="javascript:window.location.href='<?php echo _U("usergroup/edit?tab=system_manager&name=".$this->input->get("name"));?>'">
		<a style="color:red">* 注意:至少保留一个用户组，id=1的用户组无法删除</a>		
	</div>
	<?php endif;?>
	<div class="blank5" style="height:10px;"></div>
	<div id="tagscontent" class="right_box">
	<table class="datatable" style='width:100%;'>
		<thead>
			<tr>
				<th >
					<input title="点击可全选本页的所有项目" type="checkbox" id="chkall">
				</th> 
				<th>排序</th>
				<th>ID</th>
				<th><?=lang('usergroup_name')?></th>
				<th><?=lang('usergroup_type')?></th>
				<th width="168">操作</th>
			</tr>
		</thead>
		<tbody>
		 
			<?php if($usergroupes == null || sizeof($usergroupes)==0):?>
			<tr><td colspan="6">&nbsp;</td></tr>
			<?php endif;?>
			<?php foreach($usergroupes as $usergroup):
			if(!empty($_GET['id'])):
			if($usergroup->id!=$_GET['id']):
				$ci->select_html .= "<option value='$usergroup->id'>$usergroup->name</option>";
			endif;
			else:
				$ci->select_html .= "<option value='$usergroup->id'>$usergroup->name</option>";
			endif;
			?>
			<tr> 
				<td style="width:31px;">
					<input type="checkbox" value="<?php echo $usergroup->id;?>"  name="ids[]">
				</td>
				<td align="center">
					<span style="width:59px" class="hotspot" >
						<input type="text" name="listorder[<?php echo $usergroup->id?>]" value="<?php echo $usergroup->order?>" class="input_c">
					</span>
				</td>
				<td align="center">{usergroup->id}</td> 
				<td align="left">
					{usergroup->name}
				</td> 
				<td align="center">
					<?=$usergroup->type?>
				</td>
				<td align="center" width="170">
					<?php if($cu_group->permission("usergroup","edit")):?>
					<a class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();" href="<?=_U('usergroup/edit?tab=system_manager&id=')?>{usergroup->id}">
					</a>
					<?php endif;?>
					<?php if($cu_group->permission("usergroup","del")):?>
					<a class="delete" onmouseover="tooltip.show('删除');" onmouseout="tooltip.hide();" onclick="javascript:return confirm('删除用户组将会删除该组内用户，是否确认删除');" href="<?=_U('usergroup/del?tab=system_manager&id=')?>{usergroup->id}">
					</a>
					<?php endif;?>
				</td>
			</tr>
			<?if(sizeof($usergroup->children)>0){bl_usergroup($usergroup->children,1);}?>
			<?php endforeach;$ci->select_html.="</select>"?> 
		</tbody>
	</table>
<div class="blank10" style="height:10px"></div>	
<script>
$(document).ready(function(){
	$('#btn_delete').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("usergroup/del");?>'); 
		frm.submit();
	});
	$('#btn_order').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("usergroup/order");?>'); 
		frm.submit();
	});
});
</script>
<?php if($cu_group->permission("usergroup","del")):?>
<input class="btn_d" type="button" value=" 删除 " id="btn_delete">
<?php endif;?>
<?php if($cu_group->permission("usergroup","order")):?>
<input class="btn_d" type="button" value=" 排序 " id="btn_order">
<?php endif;?>
	<script> 
	/*******
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('#content',{allowFileManager : true}) ;      
	}); *****/
	$(document).ready(function(){

		var tmp = $('input[name=p_target_window]').val();
		if(tmp != '_self' && tmp !='_blank' && tmp !='') 
		{
			$('#target_window option:eq(2)').attr('value',tmp);
			$('input[name=p_target_window]').css('display',''); 
			$('#target_window').val(tmp); 
		}
		$('#target_window').change(function(){
			var v = $(this).val();
			if(v=='custom')
			{
				$('input[name=p_target_window]').css('display','');
			}
			else
			{
				$('input[name=p_target_window]').css('display','none');
			}
			$('#target_window').change();
		});
	});
	</script>
	</div>
</form>

{end} 
